﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace DrugsShopManagement.DBCLASS
{
    class ReadWriteTxtHelper
    {
        /// <summary>
        /// 写内容到txt文件
        /// </summary>
        /// <param name="FileName">文件名</param>
        /// <param name="Content">内容</param>
        public void WriteFile(string FileName, string Content)
        {
            System.IO.StreamWriter sw = new System.IO.StreamWriter(FileName, false, System.Text.Encoding.GetEncoding("gb2312"));
            try
            {
                sw.Write(Content);
                sw.Flush();
            }
            finally
            {
                if (sw != null) sw.Close();
            }
        }

        /// <summary>
        /// 读txt文件内容
        /// </summary>
        /// <param name="FileName"></param>
        public void ReadFile(string FileName)
        {
            try
            {
                System.IO.FileInfo fi = new FileInfo(@"c:\test.text");
                StreamReader sr = fi.OpenText();
                string s1 = sr.ReadToEnd(); //全读出来
                //string strLine = string.Empty;
                //while ((strLine = sr.ReadLine()) != null)
                //{
                //    //strLine //就是一行，
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
